package com.enjoyor.soa.traffic.server.tpcms.dubbo.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import com.alibaba.dubbo.config.annotation.Service;
import com.enjoyor.soa.traffic.api.dto.tpcms.ApplyZoneDto;
import com.enjoyor.soa.traffic.api.dto.tpcms.InfoZoneDto;
import com.enjoyor.soa.traffic.api.dto.tpcms.RltBayonetZoneDto;
import com.enjoyor.soa.traffic.api.service.dubbo.tpcms.IDubboInfoZoneService;
import com.enjoyor.soa.traffic.core.tpcms.domain.InfoZone;
import com.enjoyor.soa.traffic.core.tpcms.service.IApplyZoneService;
import com.enjoyor.soa.traffic.core.tpcms.service.IRltBayonetZoneService;
import com.enjoyor.soa.traffic.util.helper.ReflectHelper;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

@SuppressWarnings("rawtypes")
@Service(version = "1.0.0", timeout = 4000)
public class DubboInfoZoneService implements IDubboInfoZoneService {

    @Autowired
    private IApplyZoneService applyZoneService;

    @Autowired
    private IRltBayonetZoneService rltBayonetZoneService;

    @Value("redis.key")
    private String key;

    /**
     * 新增区域信息
     */
    @Override
    public ResultPojo insertInfoZone(ApplyZoneDto applyZoneDto, String userName) {
        applyZoneService.insertApplyZone(applyZoneDto, userName);
        return new ResultPojo();
    }

    /**
     * 删除区域信息
     */
    @Override
    public ResultPojo deleteInfoZone(String infoZoneId, String userName) {
        applyZoneService.deleteApplyZone(infoZoneId, userName);
        return new ResultPojo();
    }

    /**
     * 修改区域信息
     */
    @Override
    public ResultPojo editInfoZone(ApplyZoneDto applyZoneDto, String userName) {
        applyZoneService.editApplyZone(applyZoneDto, userName);
        return new ResultPojo();
    }

    /**
     * 查询区域信息列表
     */
    @Override
    public ResultPojo getInfoZoneList(String applyZoneId, String applyZoneName, String zoneTypeId, String isUse) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("applyZoneId", applyZoneId);
        map.put("applyZoneName", applyZoneName);
        map.put("zoneTypeId", zoneTypeId);
        map.put("isUse", isUse);
        List<ApplyZoneDto> applyZoneDtos = applyZoneService.getApplyZoneList(map);
        // 查询关联卡口数据
        for (ApplyZoneDto applyZoneDto : applyZoneDtos) {
            List<RltBayonetZoneDto> rltBayonetList = rltBayonetZoneService.getRltBayonetList(applyZoneDto.getApplyZoneId());
            applyZoneDto.setRltBayonetZones(ReflectHelper.listToList(rltBayonetList, RltBayonetZoneDto.class));
        }
        return new ResultPojo(applyZoneDtos);
    }

    /**
     * 查询区域信息分页
     */
    @Override
    public ResultPojo getInfoZonePage(Page page) {
        return new ResultPojo(applyZoneService.getApplyZonePage(page));
    }

    /**
     * 绘制地图位置信息
     */
    @Override
    public ResultPojo drawingZoneShape(InfoZoneDto infoZone, String userName) {
        applyZoneService.drawingZoneShape(ReflectHelper.beanToBean(infoZone, InfoZone.class), userName);
        return new ResultPojo();
    }

}
